var arr = [];//存所有数据
var count = 8;//一页多少条数据
var page = 1;//当前的页数

$.ajax({
    url: 'http://172.17.7.212:3000/admin/getadmin',
    success: function (res) {
        if (res.data.length) {
            arr = res.data;
            rem();
            ret();
        }

    },
})
function rem() {
    $('.motaikuang table tbody').html('');
    $.each(arr.slice((page - 1) * count, page * count), function (i, v) {
        var a = v.type == '1' ? '普通管理员' : "超级管理员";
        $('.motaikuang table tbody').append(
            '<tr>\
    <td class="th1">'+ v.id + '</td>\
    <td>'+ v.name + '</td>\
    <td>'+ v.userId + '</td>\
    <td>'+ a + '</td>\
    <td>\
            <button type="button" class="shu" data-toggle="modal" \data-target="#myModal4">\
                删除\
            </button>\
            <button type="button" class="shu" data-toggle="modal" \data-target="#exampleModal4"\
                data-whatever="@mdo">修改</button>\
    </td>\
</tr>'
        )
    })
}
$('#nav2').on('click', 'li', function () {
    page = $(this).text();
    rem();
})
console.log($('.j-add-name').text())
function ret() {
    var n = Math.ceil(arr.length / count);
    for (var i = 1; i <= n; i++) {
        $('.yeshu').before($('<li><a href="#">' + i + '</a></li>'));
    }
}
$('.j-add-btn').on('click', function () {
    // console.log(11);
    $.ajax({
        url: 'http://172.17.7.212:3000/admin/addadmin',
        data: {
            name: $('.j-add-name').val(),
            password: $('.j-add-password').val(),
            type: $('.j-add-type').val(),
            userId: $('.j-add-user').val(),
        },

        type: 'post',
        success: function (res) {
            console.log(res)
            if (res.code == 200) {
                $('#exampleModal1').modal('hide');
                rem();
            } else {
                alert('添加失败')
            }
        }
    })
})